<template>
	<!-- 巡检详情 下次预计巡检时间 -->
  <view class="flex-col ">
    <view class="flex-col">
      <view class="flex-col items-start section_3">
        <view class="group_6">
          <text class="text_11">{{this.detailedName}}</text>
          <text class="text_12">（{{this.num}}/{{this.inspectionNums}}次）</text>
        </view>
      </view>
      <view class="flex-col section_4">
        <view class="justify-between">
          <text class="text_13">下次巡检工序</text>
          <view>
			  <picker @change="bindPickerChange" :value="index" :range="array">
			  	<view class="uni-input">
			  		<text class="text_20">{{textValue}}</text>
			  		<image  :src="$IMG_URL+'index/goright.png'" class="image_4"  />
			  	</view>
			  </picker>
		  </view>
		  
        </view>
        <view class="justify-between group_8">
          <text class="text_15">预计下次巡检时间</text>
		  <view>
			  <picker mode="date" :value="date"
			  	@change="bindDateChange">
			  	<view class="flex-row">
			  		<text class="text_3 uni-input">{{date}}</text>
			  		<view class="display:inline-block">
			  			<image :src="$IMG_URL+'index/goright.png'" class="image_4" />
			  		</view>
			  	</view>
			  	
			  </picker>
		  </view>
        </view>
      </view>
    </view>
    <view class="flex-row group_9">
      <view class="flex-col items-center text-wrapper_4" @click="nextClick(0)"><text class="text_17">上一步</text></view>
      <view class="flex-col items-center text-wrapper_5" @click="nextClick(1)"><text class="text_18">确认提交</text></view>
    </view>
	<u-overlay :show="uploadloading" @click="uploadloading = false" class="u-flex u-row-center u-col-center">
		<view >
			<u-loading-icon size="30" :textSize="15" text="请求中" textColor="white" :vertical="true" color="white"></u-loading-icon>
		</view>
		
	</u-overlay>
<!-- 	<u-popup :show="uploadloading" mode="center" @close="loadingclose">
		<u-loading-icon></u-loading-icon>
	</u-popup> -->
  </view>
</template>

<script>
	export default {
		props:{
			
		},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				date: currentDate,
				index:0,
				array:[],
				num:'',
				ordersId:'',
				inspectionNums:'',
				detailedName:'',
				textValue:'',
				uploadloading:false
			}
		},
		created() {
			this.ordersId = uni.getStorageSync('ordersId');
			 this.getstoragedata();this.getprocedure();
			 uni.startPullDownRefresh();
			 setTimeout(function() {
			 	uni.stopPullDownRefresh();
			 }, 1000);
		},
		onLoad() {
			this.ordersId = uni.getStorageSync('ordersId');
			 this.getstoragedata();this.getprocedure();
		},
		methods: {
			loadingclose(){
				this.uploadloading=false
			},
			getstoragedata(){
				const ordersId = uni.getStorageSync('ordersId');
				let inspectionFrequencyId = uni.getStorageSync('inspectionFrequencyId');
				// console.log(ordersId);
				this.$http('common.getInfolist',{
					ordersId:ordersId,
					type:'5',
					inspectionFrequencyId:inspectionFrequencyId
				}).then(res=>{
					// console.log(res,'验收列表22')
					if(res.code ==200){
						this.inspectionNums = res.data.inspectionNums;
						this.num = res.data.conductNum;
						this.detailedName = res.data.detailedName;
						this.getmoren()
					}
				})
			},
			nextClick(e){
				const ordersId = uni.getStorageSync('ordersId');
				if(e ==0){
					this.$emit('getStateS', {tabProState:1,inspectionFrequencyId:false})
				}else{
					this.uploadloading=true;
					for(let i in this.list){
						if(this.textValue == this.list[i].name){
							this.index = i;
						}
					}
					this.$http('onsite.nextPatrol',{
						nextProcessId:this.list[this.index].processId,
						nextInspectionTime:this.date,
						num:this.num,
						ordersId:ordersId
					}).then(res=>{
						if(res.code ==200){
						
							uni.setStorage({
								data: res.data,
								key: 'inspectionFrequencyId',
								success:()=>{
									this.uploadloading=false;
									this.$emit('getStateS',{tabProState:2,inspectionFrequencyId:res.data})
								}
							})
							
							
						}
					})
				}
			},
			getmoren(){
				// 默认下次巡检工序'
				this.$http('other.querynextProcess',{
					num:this.num,
					ordersId:this.ordersId
				}).then(res=>{
					if(res.code ==200){
						// console.log(res.data.processName,'querynextProcess');
						this.textValue = res.data.processName;
						// console.log(this.array,this.index)
					}
				}).catch(err=>{
					
				})
			},
			getprocedure(){
				// 查询巡检工序
				this.$http('onsite.getprocedure').then(res=>{
					if(res.code ==200){
						this.list = res.data;
						for(let i=0;i<this.list.length;i++){
							this.array.push(this.list[i].name);
						}
					}
				}).catch(err=>{
					
				})
			},
			bindPickerChange(e){
				this.index = e.detail.value;
				this.textValue = this.array[e.detail.value];
			},
			bindDateChange(e) {
				this.date = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
			
			 if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
			 month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style scoped lang="scss">
  .page {
    padding-bottom: 48rpx;
    background-color: #f6f7f9ff;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
  }
  .image_4 {
    margin-left: 15rpx;
    margin-top: 9rpx;
    flex-shrink: 0;
    width: 14rpx;
    height: 26rpx;
  }
  .group_9 {
    margin-top: 144rpx;
    padding: 0 32rpx;
  }
  .section_1 {
    padding: 30.5rpx 21rpx 48rpx;
    background-image: url($IMG_URL+'16557870724016329987.png');
    background-position: 0% 0%;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    position: relative;
  }
  .section_3 {
    margin: 0 23rpx;
    padding: 39rpx 0 34rpx;
    background-image: url($IMG_URL+'16557870748916382602.png');
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  .section_4 {
    margin: 19rpx 24rpx 0;
    padding: 22rpx 22rpx 44rpx 24rpx;
    background-color: #ffffff;
    border-radius: 16rpx;
  }
  .text-wrapper_4 {
   
    flex: 1 1 326rpx;
    background-color: #ffffff;
    border-radius: 44rpx;
    height: 88rpx;
	 line-height: 88rpx;
  }
  .text-wrapper_5 {
    margin-left: 34rpx;
   
    flex: 1 1 326rpx;
    background-color: #1d6aff;
    border-radius: 44rpx;
    height: 88rpx;
	 line-height: 88rpx;
  }
  .group_1 {
    padding: 24.5rpx 10.5rpx 28rpx;
    position: relative;
  }
  .section_2 {
    padding: 0 43rpx 84rpx;
    background-image: url($IMG_URL+'16557870830617903945.png');
    background-position: 0% 0%;
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  .group_5 {
    padding: 12rpx 19rpx;
  }
  .image_2 {
    width: 40rpx;
    height: 16rpx;
    position: absolute;
    left: 84rpx;
    bottom: 30rpx;
  }
  .group_6 {
    margin-left: 25rpx;
  }
  .group_8 {
    margin-top: 39rpx;
  }
  .text_17 {
    color: #333333;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';

  }
  .text_18 {
    color: #ffffff;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    
  }
  .image {
    position: absolute;
    left: 10.5rpx;
    bottom: 24.5rpx;
    width: 21rpx;
    height: 36rpx;
  }
  .text {
    color: #333333;
    font-size: 36rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 43rpx;
  }
  .group_2 {
    padding: 47rpx 0 24rpx;
    border-bottom: solid 1rpx #ffffff3d;
  }
  .group_3 {
    margin-top: 21rpx;
  }
  .group_4 {
    margin-top: 24rpx;
  }
  .text-wrapper_1 {
    margin-top: 5rpx;
  }
  .text-wrapper_2 {
    margin-top: 5rpx;
  }
  .text-wrapper_3 {
    margin-top: 5rpx;
  }
  .text_11 {
    color: #333333;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 38rpx;
  }
  .text_12 {
    color: #1d6aff;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
  .text_13 {
    color: #666666;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_14 {
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_15 {
    margin-bottom: 6rpx;
    color: #666666;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_16 {
    margin-top: 6rpx;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .image_1 {
    border-radius: 50%;
    width: 96rpx;
    height: 96rpx;
  }
  .text_1 {
    margin-left: 32rpx;
    margin-top: 19rpx;
    color: #ffffff;
    font-size: 36rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 43rpx;
  }
  .text_2 {
    margin-top: 7rpx;
    color: #ffffff;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 38rpx;
  }
  .text_3 {
    margin-left: 18rpx;
    margin-bottom: 7rpx;
    color: #333;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 38rpx;
  }
  .text_4 {
    color: #ffffff;
    font-size: 22rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 26rpx;
  }
  .text_5 {
    margin-left: 9.5rpx;
    color: #ffffff;
    font-size: 22rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 26rpx;
  }
  .text_6 {
    margin-left: 9.5rpx;
    color: #ffffff;
    font-size: 22rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 26rpx;
  }
  .text_7 {
    color: #333333;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 38rpx;
  }
  .text_8 {
    margin-left: 8rpx;
    margin-right: 7rpx;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_9 {
    margin-left: 8rpx;
    margin-right: 7rpx;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_10 {
    margin-left: 8rpx;
    margin-right: 7rpx;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
</style>
